package fr.umlv.projet.android.andex;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import fr.umlv.projet.android.login.LoginService;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Button connexionButton = (Button)findViewById(R.id.connexionButton);
		connexionButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// Retrieve informations
				String address = ((EditText)findViewById(R.id.addressEditText)).getText().toString();
				String port = ((EditText)findViewById(R.id.portEditText)).getText().toString();
				String username = ((EditText)findViewById(R.id.usernameEditText)).getText().toString();
				String password = ((EditText)findViewById(R.id.passwordEditText)).getText().toString();
				
				// Call Login Service
				Intent loginServiceIntent = new Intent(getBaseContext(), LoginService.class);
				loginServiceIntent.putExtra("address", address);
				loginServiceIntent.putExtra("port", port);
				loginServiceIntent.putExtra("username", username);
				loginServiceIntent.putExtra("password", password);
				
				startService(loginServiceIntent);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
